package com.design.working.service.impl;

import com.design.working.dao.DeptDAO;
import com.design.working.dao.impl.DeptDAOImpl;
import com.design.working.dto.*;
import com.design.working.dto.dept.*;
import com.design.working.po.*;
import com.design.working.po.dept.*;
import com.design.working.service.DeptService;
import com.design.working.vo.*;
import com.design.working.vo.admin.StudentApplicationDetailVO;
import com.design.working.vo.admin.StudentApplicationExaminationVO;
import com.design.working.vo.admin.StudentMsgVO;
import com.design.working.vo.dept.*;

import java.util.ArrayList;
import java.util.List;

import static com.design.working.enums.OperationEnum.NO_PAGE;

/**
 * 用工部门端服务层
 */
public class DeptServiceImpl implements DeptService {

    /**
     * 秋季学期, 1
     */
    private static final String AUTUMN_TERM = "1";

    /**
     * 未处理, 0
     */
    private static final int NOT_HANDLED = 0;

    /**
     * 批准, 1
     */
    private static final int APPROVED = 1;

    /**
     * 拒绝（负数表示）, -1
     */
    private static final int REJECT_IN_MINUS = -1;

    /**
     * 拒绝（0表示）, 0
     */
    private static final int REJECT_IN_ZERO = 0;

    /**
     * 离岗, 0
     */
    private static final int LEAVE_WORK = 0;

    /**
     * 离岗, -1
     */
    private static final int LEAVE_WORK_MINUS = -1;

    /**
     * 换岗, 1
     */
    private static final int CHANGE_WORK = 1;

    /**
     * 在岗, 1
     */
    private static final int WORKING = 1;

    /**
     * 结岗, 0
     */
    private static final int WORKING_DONE = 0;

    /**
     * 缺勤, 0
     */
    private static final int NOT_ATTEND = 0;

    /**
     * 出勤, 1
     */
    private static final int ATTEND = 1;

    /**
     * 请假, 2
     */
    private static final int LEAVE = 2;

    /**
     * 男，M
     */
    private static final String MALE = "M";

    /**
     * 女，F
     */
    private static final String FEMALE = "F";

    /**
     * 无审核员, "无审核员"
     */
    private static final String NO_EDITOR = "无审核员";

    /**
     * 无意见, "无意见"
     */
    private static final String NO_TEXT = "无意见";

    /**
     * 未处理, "未处理"
     */
    private static final String NO_HANDLE_STRING = "未处理";

    /**
     * 辅导员已处理, 0
     */
    private static final int COUNSELOR_HANDLED = 0;

    /**
     * 部门员工已处理, 1
     */
    private static final int DEPT_HANDLED = 1;

    private final DeptDAO deptDAO = new DeptDAOImpl();

    /**
     * 查找本部门未审批的学生岗位申请记录
     *
     * @param uid            部门员工工号
     * @param pageControlDTO 分页信息
     * @return 查询到的本部门未审批的学生岗位申请记录
     */
    @Override
    public ResponseVO<List<DeptHandleStudentWorkApplicationVO>> selectStudentWorkApplication(Integer uid, PageControlDTO pageControlDTO) {

        //先判断该部门员工是否有负责的在运行岗位
        int deptEmployeeId = deptDAO.selectDeptEmployeeId(uid);
        if (!deptDAO.isDeptHaveResponsibleRunningJob(deptEmployeeId)){
            return ResponseVO.error("您暂时没有负责的在运行岗位！");
        }

        int size = deptDAO.selectStudentWorkApplication(uid, NO_PAGE.getVal(), pageControlDTO.getLimit()).size();
        if (size == 0){
            return ResponseVO.error("暂时没有要处理的学生申请！");
        }

        // 访问数据库
        int page = (pageControlDTO.getPage() - 1) * pageControlDTO.getLimit();
        List<DeptHandleStudentWorkApplicationVO> list = deptDAO.selectStudentWorkApplication(uid, page, pageControlDTO.getLimit());

        return ResponseVO.success(size, list);
    }



    /**
     * 审批学生的岗位申请
     *
     * @param uid 部门员工工号
     * @param deptHandleStudentApplicationDTO 部门员工对学生申请记录的审批内容
     */
    @Override
    public void insertStudentApplicationHanding(Integer uid, DeptHandleStudentApplicationDTO deptHandleStudentApplicationDTO) {

        int id = deptDAO.selectDeptEmployeeId(uid);
        deptDAO.insertStudentApplicationHanding(id, deptHandleStudentApplicationDTO);
    }

    /**
     * 查找申请表中学生申请工作填写的个人信息
     *
     * @param smtId 学生申请工作表中对应的个人信息记录id
     * @return 学生申请工作填写的个人信息
     */
    @Override
    public ResponseVO<StudentApplicationDetailVO> selectStudentApplicationDetail(Integer smtId) {

        StudentApplicationDetailPO studentApplicationDetailPO = deptDAO.selectStudentApplicationDetail(smtId);
        StudentApplicationDetailVO studentApplicationDetailVO = new StudentApplicationDetailVO();

        studentApplicationDetailVO.setPhone(studentApplicationDetailPO.getPhone());
        studentApplicationDetailVO.setEmail(studentApplicationDetailPO.getEmail());
        studentApplicationDetailVO.setPoliticalStatus(studentApplicationDetailPO.getPoliticalStatus());

        String needyStudent = null;
        switch (studentApplicationDetailPO.getNeedyStudent()) {
            case REJECT_IN_ZERO:
                needyStudent = "否";
                break;
            case APPROVED:
                needyStudent = "是";
                break;
            default:
        }
        studentApplicationDetailVO.setNeedyStudent(needyStudent);

        studentApplicationDetailVO.setDorm(studentApplicationDetailPO.getDorm());
        studentApplicationDetailVO.setStrength(studentApplicationDetailPO.getStrength());
        studentApplicationDetailVO.setFreeTime(studentApplicationDetailPO.getFreeTime());

        return ResponseVO.success(studentApplicationDetailVO);
    }

    /**
     * 查找辅导员对学生申请表的意见
     *
     * @param swaId 学生申请工作表id
     * @return 辅导员对学生申请表的意见
     */
    @Override
    public ResponseVO<DeptPreAdviceVO> selectStudentPreAdvice(Integer swaId) {

        DeptPreAdvicePO deptPreAdvicePO = deptDAO.selectStudentPreAdvice(swaId);
        DeptPreAdviceVO deptPreAdviceVO = new DeptPreAdviceVO();

        deptPreAdviceVO.setCounselor(deptPreAdvicePO.getCounselor());
        deptPreAdviceVO.setCounselorText(deptPreAdvicePO.getCounselorText());

        String counselorPassed = null;
        switch (deptPreAdvicePO.getCounselorPassed()) {
            case NOT_HANDLED:
                counselorPassed = "未处理";
                break;
            case REJECT_IN_MINUS:
                counselorPassed = "拒绝";
                break;
            case APPROVED:
                counselorPassed = "批准";
                break;
            default:
        }
        deptPreAdviceVO.setCounselorPassed(counselorPassed);

        return ResponseVO.success(deptPreAdviceVO);
    }

    /**
     * 查询学生岗位变动申请
     *
     * @param uid            部门员工工号
     * @param pageControlDTO 分页信息
     * @return 查询到的本部门未审批的学生岗位变动申请
     */
    @Override
    public ResponseVO<List<DeptHandleStudentWorkMotionVO>> selectStudentWorkMotion(Integer uid, PageControlDTO pageControlDTO) {

        //先判断该部门员工是否有负责的在运行岗位
        int deptEmployeeId = deptDAO.selectDeptEmployeeId(uid);
        if (!deptDAO.isDeptHaveResponsibleRunningJob(deptEmployeeId)){
            return ResponseVO.error("您暂时没有负责的在运行岗位！");
        }

        int size = deptDAO.selectStudentWorkMotion(uid, NO_PAGE.getVal(), pageControlDTO.getLimit()).size();
        // 如果没有需要审核的学生申请
        if (size == 0) {
            return ResponseVO.error("暂时没有要处理的学生申请！");
        }

        // 访问数据库
        int page = (pageControlDTO.getPage() - 1) * pageControlDTO.getLimit();
        List<DeptHandleStudentWorkMotionPO> temp = deptDAO.selectStudentWorkMotion(uid, page, pageControlDTO.getLimit());

        List<DeptHandleStudentWorkMotionVO> list = new ArrayList<>();
        // 转换数据
        for (DeptHandleStudentWorkMotionPO deptHandleStudentWorkMotionPO : temp) {

            DeptHandleStudentWorkMotionVO deptHandleStudentWorkMotionVO = new DeptHandleStudentWorkMotionVO();

            deptHandleStudentWorkMotionVO.setId(deptHandleStudentWorkMotionPO.getId());
            deptHandleStudentWorkMotionVO.setCollege(deptHandleStudentWorkMotionPO.getCollege());

            String majorClass = deptHandleStudentWorkMotionPO.getMajor() + "-" + deptHandleStudentWorkMotionPO.getClasses();
            deptHandleStudentWorkMotionVO.setMajorClass(majorClass);

            deptHandleStudentWorkMotionVO.setUid(deptHandleStudentWorkMotionPO.getUid());
            deptHandleStudentWorkMotionVO.setName(deptHandleStudentWorkMotionPO.getName());
            deptHandleStudentWorkMotionVO.setWorkName(deptHandleStudentWorkMotionPO.getWorkName());

            String workType = null;
            switch (deptHandleStudentWorkMotionPO.getWorkType()) {
                case LEAVE_WORK:
                    workType = "离岗";
                    break;
                case CHANGE_WORK:
                    workType = "换岗";
                    break;
                default:
            }
            deptHandleStudentWorkMotionVO.setWorkType(workType);
            deptHandleStudentWorkMotionVO.setStudentExplanation(deptHandleStudentWorkMotionPO.getStudentExplanation());

            list.add(deptHandleStudentWorkMotionVO);
        }
        return ResponseVO.success(size, list);
    }

    /**
     * 插入部门员工处理的学生岗位变更表意见
     *
     * @param uid                        部门员工uid
     * @param deptHandleStudentMotionDTO 前端传来的表单数据
     */
    @Override
    public void insertStudentMotionHanding(Integer uid, DeptHandleStudentMotionDTO deptHandleStudentMotionDTO) {

        int deptEmployeeId = deptDAO.selectDeptEmployeeId(uid);
        deptDAO.insertStudentMotionHanding(deptEmployeeId, deptHandleStudentMotionDTO);
    }

    /**
     * 查询岗位学生信息
     *
     * @param uid            部门员工工号
     * @param pageControlDTO 分页信息
     * @return 查询到的本部门的岗位学生信息
     */
    @Override
    public ResponseVO<List<DeptSelectJobStudentInfoVO>> selectJobStudentInfo(Integer uid, PageControlDTO pageControlDTO) {

        int size = deptDAO.selectJobStudentInfo(uid, NO_PAGE.getVal(), pageControlDTO.getLimit()).size();

        // 如果本部门没有岗位学生信息
        if (size == 0) {
            return ResponseVO.error("本部门暂时没有岗位学生信息！");
        }

        // 访问数据库
        int page = (pageControlDTO.getPage() - 1) * pageControlDTO.getLimit();
        List<DeptSelectJobStudentInfoPO> temp = deptDAO.selectJobStudentInfo(uid, page, pageControlDTO.getLimit());

        List<DeptSelectJobStudentInfoVO> list = new ArrayList<>();
        // 转换数据
        for (DeptSelectJobStudentInfoPO deptSelectJobStudentInfoPO : temp) {

            DeptSelectJobStudentInfoVO deptSelectJobStudentInfoVO = new DeptSelectJobStudentInfoVO();

            deptSelectJobStudentInfoVO.setCollege(deptSelectJobStudentInfoPO.getCollege());

            String majorClass = deptSelectJobStudentInfoPO.getMajor() + "-" + deptSelectJobStudentInfoPO.getClasses();
            deptSelectJobStudentInfoVO.setMajorClass(majorClass);
            deptSelectJobStudentInfoVO.setUid(deptSelectJobStudentInfoPO.getUid());
            deptSelectJobStudentInfoVO.setName(deptSelectJobStudentInfoPO.getName());

            String year = deptSelectJobStudentInfoPO.getYear() + "-" + (deptSelectJobStudentInfoPO.getYear() + 1);
            String term = AUTUMN_TERM.equals(String.valueOf(deptSelectJobStudentInfoPO.getTerm())) ? "秋冬学期" : "春夏学期";
            deptSelectJobStudentInfoVO.setYear(year);
            deptSelectJobStudentInfoVO.setTerm(term);

            deptSelectJobStudentInfoVO.setWorkName(deptSelectJobStudentInfoPO.getWorkName());

            String type = null;
            switch (deptSelectJobStudentInfoPO.getWorkType()) {
                case WORKING:
                    type = "在岗";
                    break;
                case WORKING_DONE:
                    type = "结岗";
                    break;
                case LEAVE_WORK_MINUS:
                    type = "离岗";
                    break;
                default:
            }
            deptSelectJobStudentInfoVO.setWorkType(type);
            deptSelectJobStudentInfoVO.setWorkDetail(deptSelectJobStudentInfoPO.getWorkDetail());

            list.add(deptSelectJobStudentInfoVO);
        }

        return ResponseVO.success(size, list);
    }

    /**
     * 通过学号姓名查询岗位学生信息
     *
     * @param uid            部门员工工号
     * @param pageControlDTO 分页信息
     * @param stuUid         学生学号
     * @param studentName    学生姓名
     * @return 查询到的本部门的岗位学生信息
     */
    @Override
    public ResponseVO<List<DeptSelectJobStudentInfoVO>> selectJobStudentInfoByName(Integer uid, PageControlDTO pageControlDTO, String stuUid, String studentName) {

        int size = deptDAO.selectJobStudentInfoByName(uid, NO_PAGE.getVal(), pageControlDTO.getLimit(), stuUid, studentName).size();

        // 如果没有该生的岗位学生信息
        if (size == 0) {
            return ResponseVO.error("暂时没有该生的岗位学生信息！");
        }

        // 访问数据库
        int page = (pageControlDTO.getPage() - 1) * pageControlDTO.getLimit();
        List<DeptSelectJobStudentInfoPO> temp = deptDAO.selectJobStudentInfoByName(uid, page, pageControlDTO.getLimit(), stuUid, studentName);

        List<DeptSelectJobStudentInfoVO> list = new ArrayList<>();
        // 转换数据
        for (DeptSelectJobStudentInfoPO deptSelectJobStudentInfoPO : temp) {

            DeptSelectJobStudentInfoVO deptSelectJobStudentInfoVO = new DeptSelectJobStudentInfoVO();

            deptSelectJobStudentInfoVO.setCollege(deptSelectJobStudentInfoPO.getCollege());

            String majorClass = deptSelectJobStudentInfoPO.getMajor() + "-" + deptSelectJobStudentInfoPO.getClasses();
            deptSelectJobStudentInfoVO.setMajorClass(majorClass);
            deptSelectJobStudentInfoVO.setUid(deptSelectJobStudentInfoPO.getUid());
            deptSelectJobStudentInfoVO.setName(deptSelectJobStudentInfoPO.getName());

            String year = deptSelectJobStudentInfoPO.getYear() + "-" + (deptSelectJobStudentInfoPO.getYear() + 1);
            String term = AUTUMN_TERM.equals(String.valueOf(deptSelectJobStudentInfoPO.getTerm())) ? "秋冬学期" : "春夏学期";
            deptSelectJobStudentInfoVO.setYear(year);
            deptSelectJobStudentInfoVO.setTerm(term);

            deptSelectJobStudentInfoVO.setWorkName(deptSelectJobStudentInfoPO.getWorkName());

            String type = null;
            switch (deptSelectJobStudentInfoPO.getWorkType()) {
                case WORKING:
                    type = "在岗";
                    break;
                case WORKING_DONE:
                    type = "结岗";
                    break;
                case LEAVE_WORK_MINUS:
                    type = "离岗";
                    break;
                default:
            }
            deptSelectJobStudentInfoVO.setWorkType(type);
            deptSelectJobStudentInfoVO.setWorkDetail(deptSelectJobStudentInfoPO.getWorkDetail());

            list.add(deptSelectJobStudentInfoVO);
        }

        return ResponseVO.success(size, list);
    }

    /**
     * 查询学生详细信息
     *
     * @param uid 学生学号
     * @return 学生个人详细信息
     */
    @Override
    public ResponseVO<StudentMsgVO> selectStudentMsg(Integer uid) {

        StudentMsgPO studentMsgPO = deptDAO.selectStudentMsg(uid);
        StudentMsgVO studentMsgVO = new StudentMsgVO();

        String gender = null;
        switch (studentMsgPO.getGender()) {
            case MALE:
                gender = "男";
                break;
            case FEMALE:
                gender = "女";
                break;
            default:
        }
        studentMsgVO.setGender(gender);

        studentMsgVO.setPhone(studentMsgPO.getPhone());
        studentMsgVO.setEmail(studentMsgPO.getEmail());
        studentMsgVO.setPoliticalStatus(studentMsgPO.getPoliticalStatus());

        String needyStudent = null;
        switch (studentMsgPO.getNeedStudent()) {
            case REJECT_IN_ZERO:
                needyStudent = "否";
                break;
            case APPROVED:
                needyStudent = "是";
                break;
            default:
        }
        studentMsgVO.setNeedStudent(needyStudent);

        studentMsgVO.setDorm(studentMsgPO.getDorm());
        studentMsgVO.setStrength(studentMsgPO.getStrength());

        return ResponseVO.success(studentMsgVO);
    }

    /**
     * 查询当前部门员工所属部门的学生岗位申请信息
     * @param uid            部门员工工号
     * @param pageControlDTO 分页信息
     * @return 查询到的本部门的学生岗位申请信息
     */
    @Override
    public ResponseVO<List<DeptSelectStudentApplicationVO>> selectStudentApplicationRecord(Integer uid, PageControlDTO pageControlDTO) {

        int size = deptDAO.selectStudentApplicationRecord(uid, NO_PAGE.getVal(), pageControlDTO.getLimit()).size();
        // 如果本部门没有学生申请记录
        if (size == 0) {
            return ResponseVO.error("本部门暂时没有学生申请记录！");
        }

        // 访问数据库
        int page = (pageControlDTO.getPage() - 1) * pageControlDTO.getLimit();
        List<DeptSelectStudentApplicationPO> temp = deptDAO.selectStudentApplicationRecord(uid, page, pageControlDTO.getLimit());

        List<DeptSelectStudentApplicationVO> list = new ArrayList<>();
        // 转换数据
        for (DeptSelectStudentApplicationPO deptSelectStudentApplicationPO : temp) {

            DeptSelectStudentApplicationVO deptSelectStudentApplicationVO = new DeptSelectStudentApplicationVO();

            deptSelectStudentApplicationVO.setUid(deptSelectStudentApplicationPO.getUid());
            deptSelectStudentApplicationVO.setName(deptSelectStudentApplicationPO.getName());

            String year = deptSelectStudentApplicationPO.getYear() + "-" + (deptSelectStudentApplicationPO.getYear() + 1);
            String term = AUTUMN_TERM.equals(String.valueOf(deptSelectStudentApplicationPO.getTerm())) ? "秋冬学期" : "春夏学期";
            deptSelectStudentApplicationVO.setYear(year);
            deptSelectStudentApplicationVO.setTerm(term);

            deptSelectStudentApplicationVO.setWorkName(deptSelectStudentApplicationPO.getWorkName());

            String type = null;
            switch (deptSelectStudentApplicationPO.getType()) {
                case NOT_HANDLED:
                    type = "未处理";
                    break;
                case APPROVED:
                    type = "批准";
                    break;
                case REJECT_IN_MINUS:
                    type = "拒绝";
                    break;
                default:
            }
            deptSelectStudentApplicationVO.setType(type);

            deptSelectStudentApplicationVO.setWorkDetail(deptSelectStudentApplicationPO.getWorkDetail());
            deptSelectStudentApplicationVO.setId(deptSelectStudentApplicationPO.getId());
            deptSelectStudentApplicationVO.setSmtId(deptSelectStudentApplicationPO.getSmtId());

            list.add(deptSelectStudentApplicationVO);
        }

        return ResponseVO.success(size, list);
    }

    /**
     * 通过学号姓名查询当前部门员工所属部门的学生岗位申请信息
     * @param uid            部门员工工号
     * @param pageControlDTO 分页信息
     * @param stuUid         学生学号
     * @param studentName    学生姓名
     * @return 查询到的本部门的学生岗位申请信息
     */
    @Override
    public ResponseVO<List<DeptSelectStudentApplicationVO>> selectStudentApplicationRecordByName(Integer uid, PageControlDTO pageControlDTO, String stuUid, String studentName) {

        int size = deptDAO.selectStudentApplicationRecordByName(uid, NO_PAGE.getVal(), pageControlDTO.getLimit(), stuUid, studentName).size();
        // 如果没有该生的申请记录
        if (size == 0) {
            return ResponseVO.error("暂时没有该生的申请记录！");
        }

        // 访问数据库
        int page = (pageControlDTO.getPage() - 1) * pageControlDTO.getLimit();
        List<DeptSelectStudentApplicationPO> temp = deptDAO.selectStudentApplicationRecordByName(uid, page, pageControlDTO.getLimit(), stuUid, studentName);

        List<DeptSelectStudentApplicationVO> list = new ArrayList<>();
        // 转换数据
        for (DeptSelectStudentApplicationPO deptSelectStudentApplicationPO : temp) {

            DeptSelectStudentApplicationVO deptSelectStudentApplicationVO = new DeptSelectStudentApplicationVO();

            deptSelectStudentApplicationVO.setUid(deptSelectStudentApplicationPO.getUid());
            deptSelectStudentApplicationVO.setName(deptSelectStudentApplicationPO.getName());

            String year = deptSelectStudentApplicationPO.getYear() + "-" + (deptSelectStudentApplicationPO.getYear() + 1);
            String term = AUTUMN_TERM.equals(String.valueOf(deptSelectStudentApplicationPO.getTerm())) ? "秋冬学期" : "春夏学期";
            deptSelectStudentApplicationVO.setYear(year);
            deptSelectStudentApplicationVO.setTerm(term);

            deptSelectStudentApplicationVO.setWorkName(deptSelectStudentApplicationPO.getWorkName());

            String type = null;
            switch (deptSelectStudentApplicationPO.getType()) {
                case NOT_HANDLED:
                    type = "未处理";
                    break;
                case APPROVED:
                    type = "批准";
                    break;
                case REJECT_IN_MINUS:
                    type = "拒绝";
                    break;
                default:
            }
            deptSelectStudentApplicationVO.setType(type);

            deptSelectStudentApplicationVO.setWorkDetail(deptSelectStudentApplicationPO.getWorkDetail());
            deptSelectStudentApplicationVO.setId(deptSelectStudentApplicationPO.getId());
            deptSelectStudentApplicationVO.setSmtId(deptSelectStudentApplicationPO.getSmtId());

            list.add(deptSelectStudentApplicationVO);
        }

        return ResponseVO.success(size, list);
    }

    /**
     * 查询学生岗位申请的审批详情
     * @param swaId 学生岗位申请表id
     * @return 学生岗位申请审批详情
     */
    @Override
    public ResponseVO<StudentApplicationExaminationVO> selectStuAppExamination(Integer swaId) {

        int handleType = deptDAO.isHandleStuApp(swaId);
        StudentApplicationExaminationVO studentApplicationExaminationVO = new StudentApplicationExaminationVO();

        if (handleType == COUNSELOR_HANDLED){
            StudentApplicationExaminationPO studentApplicationExaminationPO = deptDAO.selectStuAppExamination0(swaId);

            studentApplicationExaminationVO.setCounselor(studentApplicationExaminationPO.getCounselor());
            studentApplicationExaminationVO.setCounselorText(studentApplicationExaminationPO.getCounselorText());
            String counselorPassed = null;
            switch (studentApplicationExaminationPO.getCounselorPassed()) {
                case NOT_HANDLED:
                    counselorPassed = "未处理";
                    break;
                case REJECT_IN_MINUS:
                    counselorPassed = "拒绝";
                    break;
                case APPROVED:
                    counselorPassed = "批准";
                    break;
                default:
            }
            studentApplicationExaminationVO.setCounselorPassed(counselorPassed);

            //手动赋值
            studentApplicationExaminationVO.setDeptEmployee(NO_EDITOR);
            studentApplicationExaminationVO.setDeptEmployeeText(NO_TEXT);
            studentApplicationExaminationVO.setDeptEmployeePassed(NO_HANDLE_STRING);
            studentApplicationExaminationVO.setAdmin(NO_EDITOR);
            studentApplicationExaminationVO.setAdminText(NO_TEXT);
            studentApplicationExaminationVO.setAdminPassed(NO_HANDLE_STRING);

            return ResponseVO.success(studentApplicationExaminationVO);
        }

        if (handleType == DEPT_HANDLED){
            StudentApplicationExaminationPO studentApplicationExaminationPO = deptDAO.selectStuAppExamination1(swaId);

            studentApplicationExaminationVO.setCounselor(studentApplicationExaminationPO.getCounselor());
            studentApplicationExaminationVO.setCounselorText(studentApplicationExaminationPO.getCounselorText());
            String counselorPassed = null;
            switch (studentApplicationExaminationPO.getCounselorPassed()) {
                case NOT_HANDLED:
                    counselorPassed = "未处理";
                    break;
                case REJECT_IN_MINUS:
                    counselorPassed = "拒绝";
                    break;
                case APPROVED:
                    counselorPassed = "批准";
                    break;
                default:
            }
            studentApplicationExaminationVO.setCounselorPassed(counselorPassed);

            studentApplicationExaminationVO.setDeptEmployee(studentApplicationExaminationPO.getDeptEmployee());
            studentApplicationExaminationVO.setDeptEmployeeText(studentApplicationExaminationPO.getDeptEmployeeText());
            String deptEmployeePassed = null;
            switch (studentApplicationExaminationPO.getDeptEmployeePassed()) {
                case NOT_HANDLED:
                    deptEmployeePassed = "未处理";
                    break;
                case REJECT_IN_MINUS:
                    deptEmployeePassed = "拒绝";
                    break;
                case APPROVED:
                    deptEmployeePassed = "批准";
                    break;
                default:
            }
            studentApplicationExaminationVO.setDeptEmployeePassed(deptEmployeePassed);

            //手动赋值
            studentApplicationExaminationVO.setAdmin(NO_EDITOR);
            studentApplicationExaminationVO.setAdminText(NO_TEXT);
            studentApplicationExaminationVO.setAdminPassed(NO_HANDLE_STRING);

            return ResponseVO.success(studentApplicationExaminationVO);
        }

        StudentApplicationExaminationPO studentApplicationExaminationPO = deptDAO.selectStuAppExamination(swaId);

        studentApplicationExaminationVO.setCounselor(studentApplicationExaminationPO.getCounselor());
        studentApplicationExaminationVO.setCounselorText(studentApplicationExaminationPO.getCounselorText());
        String counselorPassed = null;
        switch (studentApplicationExaminationPO.getCounselorPassed()) {
            case NOT_HANDLED:
                counselorPassed = "未处理";
                break;
            case REJECT_IN_MINUS:
                counselorPassed = "拒绝";
                break;
            case APPROVED:
                counselorPassed = "批准";
                break;
            default:
        }
        studentApplicationExaminationVO.setCounselorPassed(counselorPassed);

        studentApplicationExaminationVO.setDeptEmployee(studentApplicationExaminationPO.getDeptEmployee());
        studentApplicationExaminationVO.setDeptEmployeeText(studentApplicationExaminationPO.getDeptEmployeeText());
        String deptEmployeePassed = null;
        switch (studentApplicationExaminationPO.getDeptEmployeePassed()) {
            case NOT_HANDLED:
                deptEmployeePassed = "未处理";
                break;
            case REJECT_IN_MINUS:
                deptEmployeePassed = "拒绝";
                break;
            case APPROVED:
                deptEmployeePassed = "批准";
                break;
            default:
        }
        studentApplicationExaminationVO.setDeptEmployeePassed(deptEmployeePassed);

        studentApplicationExaminationVO.setAdmin(studentApplicationExaminationPO.getAdmin());
        studentApplicationExaminationVO.setAdminText(studentApplicationExaminationPO.getAdminText());
        String adminPassed = null;
        switch (studentApplicationExaminationPO.getAdminPassed()) {
            case NOT_HANDLED:
                adminPassed = "未处理";
                break;
            case REJECT_IN_MINUS:
                adminPassed = "拒绝";
                break;
            case APPROVED:
                adminPassed = "批准";
                break;
            default:
        }
        studentApplicationExaminationVO.setAdminPassed(adminPassed);

        return ResponseVO.success(studentApplicationExaminationVO);
    }

    /**
     * 查询当前部门领导所属部门的全部在运行岗位
     * @param uid         部门员工工号
     * @param pageControlDTO 分页信息
     * @return 查询到的当前部门领导所属部门的全部在运行岗位
     */
    @Override
    public ResponseVO<List<DeptSelectWorkingJobVO>> selectDeptWorkingJob(Integer uid, PageControlDTO pageControlDTO) {

        int size = deptDAO.selectDeptWorkingJob(uid, NO_PAGE.getVal(), pageControlDTO.getLimit()).size();
        // 如果本部门没有在运行岗位
        if (size == 0) {
            return ResponseVO.error("本部门暂时没有在运行岗位！");
        }

        // 访问数据库
        int page = (pageControlDTO.getPage() - 1) * pageControlDTO.getLimit();
        List<DeptSelectWorkingJobVO> list = deptDAO.selectDeptWorkingJob(uid, page, pageControlDTO.getLimit());

        return ResponseVO.success(size, list);
    }

    /**
     * 通过岗位名称查询当前部门领导所属部门的在运行岗位
     * @param uid         部门员工工号
     * @param pageControlDTO 分页信息
     * @param jobName     搜索的岗位的岗位名称
     * @return 查询到的当前部门领导所属部门的在运行岗位
     */
    @Override
    public ResponseVO<List<DeptSelectWorkingJobVO>> selectDeptWorkingJobByName(Integer uid, PageControlDTO pageControlDTO, String jobName) {

        int size = deptDAO.selectDeptWorkingJobByName(uid, NO_PAGE.getVal(), pageControlDTO.getLimit(), jobName).size();
        // 如果该部门没有运行该岗位
        if (size == 0) {
            return ResponseVO.error("本部门暂时没有运行该岗位！");
        }

        // 访问数据库
        int page = (pageControlDTO.getPage() - 1) * pageControlDTO.getLimit();
        List<DeptSelectWorkingJobVO> list = deptDAO.selectDeptWorkingJobByName(uid, page, pageControlDTO.getLimit(), jobName);

        return ResponseVO.success(size, list);
    }

    /**
     * 插入部门领导申请删除岗位的申请信息
     *
     * @param uid                       部门员工工号
     * @param deptDeleteJobMotionDTO    前端传来的申请信息
     */
    @Override
    public void insertDeptDeleteJobMotion(Integer uid, DeptDeleteJobMotionDTO deptDeleteJobMotionDTO) {
        int deptEmployeeId = deptDAO.selectDeptEmployeeId(uid);
        deptDAO.insertDeptDeleteJobMotion(deptEmployeeId, deptDeleteJobMotionDTO);
    }

    /**
     * 插入部门领导申请发布岗位的申请信息
     *
     * @param uid                       部门员工工号
     * @param deptAddJobApplicationDTO  前端表单传来的信息
     */
    @Override
    public void insertDeptAddJobApplication(Integer uid, DeptAddJobApplicationDTO deptAddJobApplicationDTO) {
        int deptEmployeeId = deptDAO.selectDeptEmployeeId(uid);
        deptDAO.insertDeptAddJobApplication(deptEmployeeId, deptAddJobApplicationDTO);
    }

    /**
     * 查询当前部门领导的发布岗位申请的审核信息
     * @param uid            部门员工工号
     * @param pageControlDTO 分页信息
     * @return 查询到的当前部门领导的发布岗位申请的审核信息
     */
    @Override
    public ResponseVO<List<DeptJobApplicationHandleVO>> selectAddJobAppHandleRecord(Integer uid, PageControlDTO pageControlDTO) {

        int deptEmployeeId = deptDAO.selectDeptEmployeeId(uid);
        int size = deptDAO.selectAddJobAppHandleRecord(deptEmployeeId, NO_PAGE.getVal(), pageControlDTO.getLimit()).size();
        // 如果没有该部门领导的岗位发布申请审核记录
        if (size == 0) {
            return ResponseVO.error("暂时没有您的岗位发布申请审核记录！");
        }

        // 访问数据库
        int page = (pageControlDTO.getPage() - 1) * pageControlDTO.getLimit();
        List<DeptJobApplicationHandlePO> temp = deptDAO.selectAddJobAppHandleRecord(deptEmployeeId, page, pageControlDTO.getLimit());

        List<DeptJobApplicationHandleVO> list = new ArrayList<>();
        // 转换数据
        for (DeptJobApplicationHandlePO deptJobApplicationHandlePO : temp) {

            DeptJobApplicationHandleVO deptJobApplicationHandleVO = new DeptJobApplicationHandleVO();

            deptJobApplicationHandleVO.setId(deptJobApplicationHandlePO.getId());
            deptJobApplicationHandleVO.setName(deptJobApplicationHandlePO.getName());
            deptJobApplicationHandleVO.setJobCategory(deptJobApplicationHandlePO.getJobCategory());
            deptJobApplicationHandleVO.setPlace(deptJobApplicationHandlePO.getPlace());
            deptJobApplicationHandleVO.setWorkDetail(deptJobApplicationHandlePO.getWorkDetail());
            deptJobApplicationHandleVO.setNeedCount(deptJobApplicationHandlePO.getNeedCount());

            String year = deptJobApplicationHandlePO.getYear() + "-" + (deptJobApplicationHandlePO.getYear() + 1);
            String term = AUTUMN_TERM.equals(String.valueOf(deptJobApplicationHandlePO.getTerm())) ? "秋冬学期" : "春夏学期";
            deptJobApplicationHandleVO.setYear(year);
            deptJobApplicationHandleVO.setTerm(term);

            String adminStatus = null;
            switch (deptJobApplicationHandlePO.getAdminStatus()) {
                case NOT_HANDLED:
                    adminStatus = "未处理";
                    break;
                case APPROVED:
                    adminStatus = "批准";
                    break;
                case REJECT_IN_MINUS:
                    adminStatus = "拒绝";
                    break;
                default:
            }
            deptJobApplicationHandleVO.setAdminStatus(adminStatus);
            deptJobApplicationHandleVO.setDeptExplanation(deptJobApplicationHandlePO.getDeptExplanation());

            list.add(deptJobApplicationHandleVO);
        }

        return ResponseVO.success(size, list);
    }

    /**
     * 通过岗位名称查询当前部门领导的发布岗位申请的审核信息
     * @param uid         部门员工工号
     * @param pageControlDTO 分页信息
     * @param jobName     搜索的岗位的岗位名称
     * @return 查询到的当前部门领导的发布岗位申请的审核信息
     */
    @Override
    public ResponseVO<List<DeptJobApplicationHandleVO>> selectAddJobAppHandleRecordByName(Integer uid, PageControlDTO pageControlDTO, String jobName) {

        int deptEmployeeId = deptDAO.selectDeptEmployeeId(uid);
        int size = deptDAO.selectAddJobAppHandleRecordByName(deptEmployeeId, NO_PAGE.getVal(), pageControlDTO.getLimit(), jobName).size();
        // 如果没有该岗位的发布申请审核记录
        if (size == 0) {
            return ResponseVO.error("暂时没有该岗位的发布申请审核记录！");
        }

        // 访问数据库
        int page = (pageControlDTO.getPage() - 1) * pageControlDTO.getLimit();
        List<DeptJobApplicationHandlePO> temp = deptDAO.selectAddJobAppHandleRecordByName(deptEmployeeId, page, pageControlDTO.getLimit(), jobName);

        List<DeptJobApplicationHandleVO> list = new ArrayList<>();
        // 转换数据
        for (DeptJobApplicationHandlePO deptJobApplicationHandlePO : temp) {

            DeptJobApplicationHandleVO deptJobApplicationHandleVO = new DeptJobApplicationHandleVO();

            deptJobApplicationHandleVO.setId(deptJobApplicationHandlePO.getId());
            deptJobApplicationHandleVO.setName(deptJobApplicationHandlePO.getName());
            deptJobApplicationHandleVO.setJobCategory(deptJobApplicationHandlePO.getJobCategory());
            deptJobApplicationHandleVO.setPlace(deptJobApplicationHandlePO.getPlace());
            deptJobApplicationHandleVO.setWorkDetail(deptJobApplicationHandlePO.getWorkDetail());
            deptJobApplicationHandleVO.setNeedCount(deptJobApplicationHandlePO.getNeedCount());

            String year = deptJobApplicationHandlePO.getYear() + "-" + (deptJobApplicationHandlePO.getYear() + 1);
            String term = AUTUMN_TERM.equals(String.valueOf(deptJobApplicationHandlePO.getTerm())) ? "秋冬学期" : "春夏学期";
            deptJobApplicationHandleVO.setYear(year);
            deptJobApplicationHandleVO.setTerm(term);

            String adminStatus = null;
            switch (deptJobApplicationHandlePO.getAdminStatus()) {
                case NOT_HANDLED:
                    adminStatus = "未处理";
                    break;
                case APPROVED:
                    adminStatus = "批准";
                    break;
                case REJECT_IN_MINUS:
                    adminStatus = "拒绝";
                    break;
                default:
            }
            deptJobApplicationHandleVO.setAdminStatus(adminStatus);
            deptJobApplicationHandleVO.setDeptExplanation(deptJobApplicationHandlePO.getDeptExplanation());

            list.add(deptJobApplicationHandleVO);
        }

        return ResponseVO.success(size, list);
    }

    /**
     * 查询当前发布岗位申请的审批信息
     * @param djaId 学生岗位申请表id
     * @return 查询到的当前发布岗位申请的审批信息
     */
    @Override
    public ResponseVO<DeptJobAppExaminationVO> selectAddJobAppExamination(Integer djaId) {
        return ResponseVO.success(deptDAO.selectAddJobAppExamination(djaId));
    }

    /**
     * 查询当前部门领导的删除岗位申请的审核信息
     * @param uid         部门员工工号
     * @param pageControlDTO 分页信息
     * @return 查询到的当前部门领导的删除岗位申请的审核信息
     */
    @Override
    public ResponseVO<List<DeptJobApplicationHandleVO>> selectDeleteJobAppHandleRecord(Integer uid, PageControlDTO pageControlDTO) {

        int deptEmployeeId = deptDAO.selectDeptEmployeeId(uid);
        int size = deptDAO.selectDeleteJobAppHandleRecord(deptEmployeeId, NO_PAGE.getVal(), pageControlDTO.getLimit()).size();
        // 如果没有该部门领导的岗位删除申请审核记录
        if (size == 0) {
            return ResponseVO.error("暂时没有您的岗位删除申请审核记录！");
        }

        // 访问数据库
        int page = (pageControlDTO.getPage() - 1) * pageControlDTO.getLimit();
        List<DeptJobApplicationHandlePO> temp = deptDAO.selectDeleteJobAppHandleRecord(deptEmployeeId, page, pageControlDTO.getLimit());

        List<DeptJobApplicationHandleVO> list = new ArrayList<>();
        // 转换数据
        for (DeptJobApplicationHandlePO deptJobApplicationHandlePO : temp) {

            DeptJobApplicationHandleVO deptJobApplicationHandleVO = new DeptJobApplicationHandleVO();

            deptJobApplicationHandleVO.setId(deptJobApplicationHandlePO.getId());
            deptJobApplicationHandleVO.setName(deptJobApplicationHandlePO.getName());
            deptJobApplicationHandleVO.setJobCategory(deptJobApplicationHandlePO.getJobCategory());
            deptJobApplicationHandleVO.setPlace(deptJobApplicationHandlePO.getPlace());
            deptJobApplicationHandleVO.setWorkDetail(deptJobApplicationHandlePO.getWorkDetail());
            deptJobApplicationHandleVO.setNeedCount(deptJobApplicationHandlePO.getNeedCount());

            String year = deptJobApplicationHandlePO.getYear() + "-" + (deptJobApplicationHandlePO.getYear() + 1);
            String term = AUTUMN_TERM.equals(String.valueOf(deptJobApplicationHandlePO.getTerm())) ? "秋冬学期" : "春夏学期";
            deptJobApplicationHandleVO.setYear(year);
            deptJobApplicationHandleVO.setTerm(term);

            String adminStatus = null;
            switch (deptJobApplicationHandlePO.getAdminStatus()) {
                case NOT_HANDLED:
                    adminStatus = "未处理";
                    break;
                case APPROVED:
                    adminStatus = "批准";
                    break;
                case REJECT_IN_MINUS:
                    adminStatus = "拒绝";
                    break;
                default:
            }
            deptJobApplicationHandleVO.setAdminStatus(adminStatus);
            deptJobApplicationHandleVO.setDeptExplanation(deptJobApplicationHandlePO.getDeptExplanation());

            list.add(deptJobApplicationHandleVO);
        }
        return ResponseVO.success(size, list);
    }

    /**
     * 通过岗位名称查询当前部门领导的删除岗位申请的审核信息
     * @param uid         部门员工工号
     * @param pageControlDTO 分页信息
     * @param jobName     搜索的岗位的岗位名称
     * @return 查询到的当前部门领导的删除岗位申请的审核信息
     */
    @Override
    public ResponseVO<List<DeptJobApplicationHandleVO>> selectDeleteJobAppHandleRecordByName(Integer uid, PageControlDTO pageControlDTO, String jobName) {

        int deptEmployeeId = deptDAO.selectDeptEmployeeId(uid);
        int size = deptDAO.selectDeleteJobAppHandleRecordByName(deptEmployeeId, NO_PAGE.getVal(), pageControlDTO.getLimit(), jobName).size();
        // 如果没有该岗位的删除申请审核记录
        if (size == 0) {
            return ResponseVO.error("暂时没有该岗位的删除申请审核记录！");
        }

        // 访问数据库
        int page = (pageControlDTO.getPage() - 1) * pageControlDTO.getLimit();
        List<DeptJobApplicationHandlePO> temp = deptDAO.selectDeleteJobAppHandleRecordByName(deptEmployeeId, page, pageControlDTO.getLimit(),jobName);

        List<DeptJobApplicationHandleVO> list = new ArrayList<>();
        // 转换数据
        for (DeptJobApplicationHandlePO deptJobApplicationHandlePO : temp) {

            DeptJobApplicationHandleVO deptJobApplicationHandleVO = new DeptJobApplicationHandleVO();

            deptJobApplicationHandleVO.setId(deptJobApplicationHandlePO.getId());
            deptJobApplicationHandleVO.setName(deptJobApplicationHandlePO.getName());
            deptJobApplicationHandleVO.setJobCategory(deptJobApplicationHandlePO.getJobCategory());
            deptJobApplicationHandleVO.setPlace(deptJobApplicationHandlePO.getPlace());
            deptJobApplicationHandleVO.setWorkDetail(deptJobApplicationHandlePO.getWorkDetail());
            deptJobApplicationHandleVO.setNeedCount(deptJobApplicationHandlePO.getNeedCount());

            String year = deptJobApplicationHandlePO.getYear() + "-" + (deptJobApplicationHandlePO.getYear() + 1);
            String term = AUTUMN_TERM.equals(String.valueOf(deptJobApplicationHandlePO.getTerm())) ? "秋冬学期" : "春夏学期";
            deptJobApplicationHandleVO.setYear(year);
            deptJobApplicationHandleVO.setTerm(term);

            String adminStatus = null;
            switch (deptJobApplicationHandlePO.getAdminStatus()) {
                case NOT_HANDLED:
                    adminStatus = "未处理";
                    break;
                case APPROVED:
                    adminStatus = "批准";
                    break;
                case REJECT_IN_MINUS:
                    adminStatus = "拒绝";
                    break;
                default:
            }
            deptJobApplicationHandleVO.setAdminStatus(adminStatus);
            deptJobApplicationHandleVO.setDeptExplanation(deptJobApplicationHandlePO.getDeptExplanation());

            list.add(deptJobApplicationHandleVO);
        }
        return ResponseVO.success(size, list);
    }

    /**
     * 查询当前删除岗位申请的审批信息
     * @param djmId 学生岗位变动表id
     * @return 查询到的当前删除岗位申请的审批信息
     */
    @Override
    public ResponseVO<DeptJobAppExaminationVO> selectDeleteJobAppExamination(Integer djmId) {
        return ResponseVO.success(deptDAO.selectDeleteJobAppExamination(djmId));
    }

    /**
     * 查询当前部门员工是否为部门领导（领导才能发布/删除岗位和查询岗位审核记录）
     *
     * @param  uid  部门员工工号
     * @return true-是; false-不是
     */
    @Override
    public boolean isLeaderToDept(Integer uid) {
        return deptDAO.isLeaderToDept(uid);
    }

    /**
     * 查询当前部门员工所属部门的全部已下线岗位
     * @param uid         部门员工工号
     * @param pageControlDTO 分页信息
     * @return 查询到的当前部门员工所属部门的全部已下线岗位
     */
    @Override
    public ResponseVO<List<DeptSelectOfflineJobVO>> selectDeptOfflineJob(Integer uid, PageControlDTO pageControlDTO) {

        int size = deptDAO.selectDeptOfflineJob(uid, NO_PAGE.getVal(), pageControlDTO.getLimit()).size();
        // 如果本部门没有已下线岗位
        if (size == 0) {
            return ResponseVO.error("本部门暂时没有已下线岗位！");
        }

        // 访问数据库
        int page = (pageControlDTO.getPage() - 1) * pageControlDTO.getLimit();
        List<DeptSelectOfflineJobVO> list = deptDAO.selectDeptOfflineJob(uid, page, pageControlDTO.getLimit());

        return ResponseVO.success(size, list);
    }

    /**
     * 通过岗位名称查询当前部门员工所属部门的已下线岗位
     * @param uid         部门员工工号
     * @param pageControlDTO 分页信息
     * @param jobName     搜索的岗位的岗位名称
     * @return 查询到的当前部门员工所属部门的已下线岗位
     */
    @Override
    public ResponseVO<List<DeptSelectOfflineJobVO>> selectDeptOfflineJobByName(Integer uid, PageControlDTO pageControlDTO, String jobName) {

        int size = deptDAO.selectDeptOfflineJobByName(uid, NO_PAGE.getVal(), pageControlDTO.getLimit(), jobName).size();
        // 如果本部门的已下线岗位中没有该岗位
        if (size == 0) {
            return ResponseVO.error("本部门已下线岗位中暂时没有该岗位！");
        }

        // 访问数据库
        int page = (pageControlDTO.getPage() - 1) * pageControlDTO.getLimit();
        List<DeptSelectOfflineJobVO> list = deptDAO.selectDeptOfflineJobByName(uid, page, pageControlDTO.getLimit(), jobName);

        return ResponseVO.success(size, list);
    }

    /**
     * 查询该部门已下线岗位的下线审核信息
     * @param jobId 岗位id
     * @return 查询到的该部门已下线岗位的下线审核信息
     */
    @Override
    public ResponseVO<DeptOfflineJobExaminationVO> selectDeptOfflineJobExamination(Integer jobId) {
        return ResponseVO.success(deptDAO.selectDeptOfflineJobExamination(jobId));
    }

    /**
     * 查询目前属于在岗状态的岗位学生信息
     * @param uid            部门员工工号
     * @param pageControlDTO 分页信息
     * @return 查询到的目前属于在岗状态的岗位学生信息
     */
    @Override
    public ResponseVO<List<DeptSelectWorkingJobStudentVO>> selectDeptWorkingJobStudent(Integer uid, PageControlDTO pageControlDTO) {

        int size = deptDAO.selectDeptWorkingJobStudent(uid, NO_PAGE.getVal(), pageControlDTO.getLimit()).size();
        // 如果本部门的没有属于在岗状态的岗位学生信息
        if (size == 0) {
            return ResponseVO.error("本部门暂时没有属于在岗状态的岗位学生信息！");
        }

        // 访问数据库
        int page = (pageControlDTO.getPage() - 1) * pageControlDTO.getLimit();
        List<DeptSelectWorkingJobStudentVO> list = deptDAO.selectDeptWorkingJobStudent(uid, page, pageControlDTO.getLimit());

        return ResponseVO.success(size, list);
    }

    /**
     * 通过学号姓名查询目前属于在岗状态的岗位学生信息
     * @param uid            部门员工工号
     * @param pageControlDTO 分页信息
     * @param stuUid         学生学号
     * @param studentName    学生姓名
     * @return 查询到的目前属于在岗状态的岗位学生信息
     */
    @Override
    public ResponseVO<List<DeptSelectWorkingJobStudentVO>> selectDeptWorkingJobStudentByName(Integer uid, PageControlDTO pageControlDTO, String stuUid, String studentName) {

        int size = deptDAO.selectDeptWorkingJobStudentByName(uid, NO_PAGE.getVal(), pageControlDTO.getLimit(), stuUid, studentName).size();
        // 如果该部门的没有该生在岗状态的岗位学生信息
        if (size == 0) {
            return ResponseVO.error("本部门暂时没有该生在岗状态的岗位学生信息！");
        }

        // 访问数据库
        int page = (pageControlDTO.getPage() - 1) * pageControlDTO.getLimit();
        List<DeptSelectWorkingJobStudentVO> list = deptDAO.selectDeptWorkingJobStudentByName(uid, page, pageControlDTO.getLimit(), stuUid, studentName);

        return ResponseVO.success(size, list);
    }

    /**
     * 插入部门员工考勤学生岗位信息
     *
     * @param uid                         部门员工工号
     * @param deptHandleStudentAttendDTO  前端表单传来的考勤信息
     */
    @Override
    public void insertDeptStudentAttendInfo(Integer uid, DeptHandleStudentAttendDTO deptHandleStudentAttendDTO) {
        int deptEmployeeId = deptDAO.selectDeptEmployeeId(uid);
        deptDAO.insertDeptStudentAttendInfo(deptEmployeeId, deptHandleStudentAttendDTO);
    }

    /**
     * 查询该部门岗位的学生考勤记录
     * @param uid            部门员工工号
     * @param pageControlDTO 分页信息
     * @return 查询到的该部门岗位的学生考勤记录
     */
    @Override
    public ResponseVO<List<DeptStudentAttendanceRecordVO>> selectDeptStudentAttendance(Integer uid, PageControlDTO pageControlDTO) {

        int size = deptDAO.selectDeptStudentAttendance(uid, NO_PAGE.getVal(), pageControlDTO.getLimit()).size();
        // 如果本部门没有学生考勤记录
        if (size == 0) {
            return ResponseVO.error("本部门暂时没有学生考勤记录！");
        }

        // 访问数据库
        int page = (pageControlDTO.getPage() - 1) * pageControlDTO.getLimit();
        List<DeptStudentAttendanceRecordPO> temp = deptDAO.selectDeptStudentAttendance(uid, page, pageControlDTO.getLimit());

        List<DeptStudentAttendanceRecordVO> list = new ArrayList<>();
        // 转换数据
        for (DeptStudentAttendanceRecordPO deptStudentAttendanceRecordPO : temp) {

            DeptStudentAttendanceRecordVO deptStudentAttendanceRecordVO = new DeptStudentAttendanceRecordVO();

            deptStudentAttendanceRecordVO.setUid(deptStudentAttendanceRecordPO.getUid());
            deptStudentAttendanceRecordVO.setName(deptStudentAttendanceRecordPO.getName());

            String year = deptStudentAttendanceRecordPO.getYear() + "-" + (deptStudentAttendanceRecordPO.getYear() + 1);
            String term = AUTUMN_TERM.equals(String.valueOf(deptStudentAttendanceRecordPO.getTerm())) ? "秋冬学期" : "春夏学期";
            deptStudentAttendanceRecordVO.setYear(year);
            deptStudentAttendanceRecordVO.setTerm(term);

            deptStudentAttendanceRecordVO.setWorkName(deptStudentAttendanceRecordPO.getWorkName());
            deptStudentAttendanceRecordVO.setEmployer(deptStudentAttendanceRecordPO.getEmployer());
            deptStudentAttendanceRecordVO.setDate(deptStudentAttendanceRecordPO.getDate());

            String workType = null;
            switch (deptStudentAttendanceRecordPO.getType()) {
                case NOT_ATTEND:
                    workType = "缺勤";
                    break;
                case ATTEND:
                    workType = "出勤";
                    break;
                case LEAVE:
                    workType = "请假";
                    break;
                default:
            }
            deptStudentAttendanceRecordVO.setType(workType);

            list.add(deptStudentAttendanceRecordVO);
        }

        return ResponseVO.success(size, list);
    }

    /**
     * 通过条件（学号姓名时间）查询该部门岗位的学生考勤记录
     * @param uid            部门员工工号
     * @param pageControlDTO 分页信息
     * @param searchDTO 搜索的信息
     * @return 查询到的通过条件（学号姓名时间）查询该部门岗位的学生考勤记录
     */
    @Override
    public ResponseVO<List<DeptStudentAttendanceRecordVO>> selectDeptStudentAttendanceByLimit(Integer uid, PageControlDTO pageControlDTO, SearchDeptStudentAttendanceDTO searchDTO) {

        int size;
        // 如果不走时间查询
        if (searchDTO.getBeginDate() == null && searchDTO.getEndDate() == null) {
            size = deptDAO.selectDeptStudentAttendanceByName(uid, NO_PAGE.getVal(), pageControlDTO.getLimit(), searchDTO).size();
        } else {
            size = deptDAO.selectDeptStudentAttendanceByTime(uid, NO_PAGE.getVal(), pageControlDTO.getLimit(), searchDTO).size();
        }

        // 如果没有考勤记录
        if (size == 0) {
            return ResponseVO.error("暂时没有考勤记录！");
        }

        // 访问数据库
        int page = (pageControlDTO.getPage() - 1) * pageControlDTO.getLimit();

        List<DeptStudentAttendanceRecordPO> temp;
        // 如果不走时间查询
        if (searchDTO.getBeginDate() == null && searchDTO.getEndDate() == null) {
            temp = deptDAO.selectDeptStudentAttendanceByName(uid, page, pageControlDTO.getLimit(), searchDTO);
        } else {
            temp = deptDAO.selectDeptStudentAttendanceByTime(uid, page, pageControlDTO.getLimit(), searchDTO);
        }

        List<DeptStudentAttendanceRecordVO> list = new ArrayList<>();

        // 转换数据
        for (DeptStudentAttendanceRecordPO deptStudentAttendanceRecordPO : temp) {

            DeptStudentAttendanceRecordVO deptStudentAttendanceRecordVO = new DeptStudentAttendanceRecordVO();

            deptStudentAttendanceRecordVO.setUid(deptStudentAttendanceRecordPO.getUid());
            deptStudentAttendanceRecordVO.setName(deptStudentAttendanceRecordPO.getName());

            String year = deptStudentAttendanceRecordPO.getYear() + "-" + (deptStudentAttendanceRecordPO.getYear() + 1);
            String term = AUTUMN_TERM.equals(String.valueOf(deptStudentAttendanceRecordPO.getTerm())) ? "秋冬学期" : "春夏学期";
            deptStudentAttendanceRecordVO.setYear(year);
            deptStudentAttendanceRecordVO.setTerm(term);

            deptStudentAttendanceRecordVO.setWorkName(deptStudentAttendanceRecordPO.getWorkName());
            deptStudentAttendanceRecordVO.setEmployer(deptStudentAttendanceRecordPO.getEmployer());
            deptStudentAttendanceRecordVO.setDate(deptStudentAttendanceRecordPO.getDate());

            String workType = null;
            switch (deptStudentAttendanceRecordPO.getType()) {
                case NOT_ATTEND:
                    workType = "缺勤";
                    break;
                case ATTEND:
                    workType = "出勤";
                    break;
                case LEAVE:
                    workType = "请假";
                    break;
                default:
            }
            deptStudentAttendanceRecordVO.setType(workType);

            list.add(deptStudentAttendanceRecordVO);
        }

        return ResponseVO.success(size, list);
    }

    /**
     * 查询目前属于结岗/离岗状态的岗位学生信息
     * @param uid            部门员工工号
     * @param pageControlDTO 分页信息
     * @return 查询到的目前属于结岗/离岗状态的岗位学生信息
     */
    @Override
    public ResponseVO<List<DeptSelectEndJobStudentVO>> selectDeptEndJobStudent(Integer uid, PageControlDTO pageControlDTO) {

        int size = deptDAO.selectDeptEndJobStudent(uid, NO_PAGE.getVal(), pageControlDTO.getLimit()).size();
        // 如果该部门员工没有待评价的用工信息
        if (size == 0) {
            return ResponseVO.error("您暂时没有待评价的用工信息！");
        }

        // 访问数据库
        int page = (pageControlDTO.getPage() - 1) * pageControlDTO.getLimit();
        List<DeptSelectEndJobStudentPO> temp = deptDAO.selectDeptEndJobStudent(uid, page, pageControlDTO.getLimit());

        List<DeptSelectEndJobStudentVO> list = new ArrayList<>();
        // 转换数据
        for (DeptSelectEndJobStudentPO deptSelectEndJobStudentPO : temp) {

            DeptSelectEndJobStudentVO deptSelectEndJobStudentVO = new DeptSelectEndJobStudentVO();

            deptSelectEndJobStudentVO.setId(deptSelectEndJobStudentPO.getId());
            deptSelectEndJobStudentVO.setCollege(deptSelectEndJobStudentPO.getCollege());

            String majorClass = deptSelectEndJobStudentPO.getMajor() + "-" + deptSelectEndJobStudentPO.getClasses();
            deptSelectEndJobStudentVO.setMajorClass(majorClass);

            deptSelectEndJobStudentVO.setUid(deptSelectEndJobStudentPO.getUid());
            deptSelectEndJobStudentVO.setName(deptSelectEndJobStudentPO.getName());

            String year = deptSelectEndJobStudentPO.getYear() + "-" + (deptSelectEndJobStudentPO.getYear() + 1);
            String term = AUTUMN_TERM.equals(String.valueOf(deptSelectEndJobStudentPO.getTerm())) ? "秋冬学期" : "春夏学期";
            deptSelectEndJobStudentVO.setYear(year);
            deptSelectEndJobStudentVO.setTerm(term);

            deptSelectEndJobStudentVO.setWorkName(deptSelectEndJobStudentPO.getWorkName());
            deptSelectEndJobStudentVO.setJobCategory(deptSelectEndJobStudentPO.getJobCategory());
            deptSelectEndJobStudentVO.setPlace(deptSelectEndJobStudentPO.getPlace());
            deptSelectEndJobStudentVO.setWorkDetail(deptSelectEndJobStudentPO.getWorkDetail());

            list.add(deptSelectEndJobStudentVO);
        }

        return ResponseVO.success(size, list);
    }

    /**
     * 插入部门员工对学生的用工评价
     *
     * @param uid                         部门员工工号
     * @param deptEvaluateStudentDTO   前端表单传来的评价信息
     */
    @Override
    public void insertDeptEvaluateStuInfo(Integer uid, DeptEvaluateStudentDTO deptEvaluateStudentDTO) {
        int deptEmployeeId = deptDAO.selectDeptEmployeeId(uid);
        deptDAO.insertDeptEvaluateStuInfo(deptEmployeeId, deptEvaluateStudentDTO);
    }

    /**
     * 查询历史评价记录
     * @param uid            部门员工工号
     * @param pageControlDTO 分页信息
     * @return 查询到的历史评价记录
     */
    @Override
    public ResponseVO<List<DeptEvaluateRecordVO>> selectDeptEvaluateRecord(Integer uid, PageControlDTO pageControlDTO) {

        int deptEmployeeId = deptDAO.selectDeptEmployeeId(uid);
        int size = deptDAO.selectDeptEvaluateRecord(deptEmployeeId, NO_PAGE.getVal(), pageControlDTO.getLimit()).size();
        // 如果该部门员工没有历史评价记录
        if (size == 0) {
            return ResponseVO.error("您暂时没有历史评价记录！");
        }

        // 访问数据库
        int page = (pageControlDTO.getPage() - 1) * pageControlDTO.getLimit();
        List<DeptEvaluateRecordPO> temp = deptDAO.selectDeptEvaluateRecord(deptEmployeeId, page, pageControlDTO.getLimit());

        List<DeptEvaluateRecordVO> list = new ArrayList<>();
        // 转换数据
        for (DeptEvaluateRecordPO deptEvaluateRecordPO : temp) {

            DeptEvaluateRecordVO deptEvaluateRecordVO = new DeptEvaluateRecordVO();

            deptEvaluateRecordVO.setId(deptEvaluateRecordPO.getId());
            deptEvaluateRecordVO.setCollege(deptEvaluateRecordPO.getCollege());

            String majorClass = deptEvaluateRecordPO.getMajor() + "-" + deptEvaluateRecordPO.getClasses();
            deptEvaluateRecordVO.setMajorClass(majorClass);

            deptEvaluateRecordVO.setUid(deptEvaluateRecordPO.getUid());
            deptEvaluateRecordVO.setName(deptEvaluateRecordPO.getName());

            String year = deptEvaluateRecordPO.getYear() + "-" + (deptEvaluateRecordPO.getYear() + 1);
            String term = AUTUMN_TERM.equals(String.valueOf(deptEvaluateRecordPO.getTerm())) ? "秋冬学期" : "春夏学期";
            deptEvaluateRecordVO.setYear(year);
            deptEvaluateRecordVO.setTerm(term);

            deptEvaluateRecordVO.setWorkName(deptEvaluateRecordPO.getWorkName());
            deptEvaluateRecordVO.setJobCategory(deptEvaluateRecordPO.getJobCategory());
            deptEvaluateRecordVO.setPlace(deptEvaluateRecordPO.getPlace());
            deptEvaluateRecordVO.setWorkDetail(deptEvaluateRecordPO.getWorkDetail());
            deptEvaluateRecordVO.setEvaluation(deptEvaluateRecordPO.getEvaluation());

            list.add(deptEvaluateRecordVO);
        }

        return ResponseVO.success(size, list);
    }
}
